package com.example.managerback.controller;
import com.example.managerback.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import com.example.managerback.service.EmployeeService;
import com.example.managerback.utils.BaseResult;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class Hello {

    @Autowired
    EmployeeService employeeService;

    @GetMapping("/hello")
    public BaseResult hello(){
        return BaseResult.success("服务器数据");
    }

    @GetMapping("/age")
    public void test(){
         throw  new CustomException("502","服务器出现问题");

    }

    @GetMapping("/map")
    public BaseResult getInfo() {
        HashMap<String, String> map = new HashMap<>();
        map.put("username", "张三");
        map.put("password", "admin");
        map.put("age", "20");
        return BaseResult.success(map);
    }

    @GetMapping("/getAll")
    public BaseResult getAll(){
        return BaseResult.success(employeeService.setAll());
    }
//    查询id
    @GetMapping("/selectById/{id}")
    public BaseResult getById(@PathVariable("id") Integer id){
        return BaseResult.success(employeeService.setById(id));
    }

}
